package com.focusai.efairy.model.request;

import com.focusai.efairy.model.base.UpLoadBaseEntity;
import com.focusai.efairy.network.Response;
import com.focusai.efairy.network.exception.ParseException;
import com.focusai.efairy.network.request.base.PureJSONRequest;
import com.focusai.efairy.network.utils.UrlUtils;
import com.focusai.efairy.utils.GsonHelper;

import org.json.JSONException;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by luo_guangwen on 2017/9/16.
 */

public class AddUserAndDevToProjectRequest extends PureJSONRequest<String> {
    private String phone;
    private String name;
    private String efairyproject_id;
    private List<Long> devIds;
    public AddUserAndDevToProjectRequest(String projectId, String phone, String name,List<Long> devIds, Response.Listener<String> listener) {
        super(UrlUtils.createUrl("/appapi/manage_project_user_and_user_device"), listener);
        this.phone = phone;
        this.name = name;
        this.efairyproject_id = projectId;
        this.devIds = devIds;
    }

    @Override
    protected String parse(String result) throws ParseException {
        return result;
    }

    @Override
    public Map<String, String> getParams() throws JSONException {
        return super.getParams();
    }

    @Override
    public String getPureJSON() throws JSONException {
        if (devIds == null)
            devIds = new ArrayList<>();
        UploadEntry uploadEntry = new UploadEntry();
        uploadEntry.efairyproject_id = efairyproject_id;
        uploadEntry.efairyuser_phonenumber = phone;
        uploadEntry.efairyuser_nickname = name;
        uploadEntry.efairydevice_id_list = devIds;
        return GsonHelper.getInstance().toJson(uploadEntry);
    }

    private static class UploadEntry extends UpLoadBaseEntity {
        public String efairyproject_id;
        public String efairyuser_phonenumber;
        public String efairyuser_nickname;
        public List<Long> efairydevice_id_list;
    }

}

